package cn.tedu.datamanager.controller;

import cn.tedu.datamanager.pojo.dto.ServeAddNewDTO;
import cn.tedu.datamanager.pojo.vo.ServeListItemVO;
import cn.tedu.datamanager.serve.IServeService;
import cn.tedu.datamanager.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


@Slf4j
@Api(tags = "01. 项目类别模块")
@RestController
@RequestMapping("/serve")
public class ServeController {
    @Autowired
    IServeService Service;

    // http://localhost:9081/serve
    @ApiOperation("查询项目类别列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<ServeListItemVO>> list() {
        log.debug("开始处理【查询项目类别列表】的请求");
        List<ServeListItemVO> list = Service.list();
        return JsonResult.ok(list);
    }

    // http://localhost:8080/serve/add-new?xxxx
    @ApiOperation("添加项目类别")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated ServeAddNewDTO serveAddNewDTO) {
        log.debug("开始处理【添加项目类别】的请求，参数：{}", serveAddNewDTO);
        Service.addNew(serveAddNewDTO);
        return JsonResult.ok();
    }

    // http://localhost:8080/serve/9527/delete
    @ApiOperation("删除项目类别")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "serveId", value = "项目类别id", required = true, dataType = "long")
    @PostMapping("/{serveId:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long serveId) {
        log.debug("开始处理【删除管理员】的请求，参数：{}", serveId);
        Service.delete(serveId);
        return JsonResult.ok();
    }

    // http://localhost:9081/serve/xx/enable
    @ApiOperation("启用项目类别")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "serveId", value = "项目serveId", required = true, dataType = "long")
    @PostMapping("/{serveId:[0-9]+}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long serveId) {
        log.debug("开始处理【启用项目类别】的请求，参数：{}", serveId);
        Service.setEnable(serveId);
        return JsonResult.ok();
    }

    // http://localhost:9081/serve/xx/disable
    @ApiOperation("停用项目类别")
    @ApiOperationSupport(order = 311)
    @ApiImplicitParam(name = "serveId", value = "管理员id", required = true, dataType = "long")
    @PostMapping("/{serveId:[0-9]+}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long serveId) {
        log.debug("开始处理【停用项目类别】的请求，参数：{}", serveId);
        Service.setDisable(serveId);
        return JsonResult.ok();
    }
}
